package cn.wsh.basic.service.impl;

import cn.wsh.basic.mapper.BaseMapper;
import cn.wsh.basic.query.BaseQuery;
import cn.wsh.basic.service.IBaseService;
import cn.wsh.basic.util.PageList;
import cn.wsh.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : BaseServiceImpl
 * Author : "吴----"
 * @date : 2022/1/24 15:46
 */

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;


    @Override
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void remove(Long id) {
        mapper.delete(id);
    }

    @Override
    public T queryById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {

        //查询总条数
        Long total = mapper.queryCount(query);
        // 查询当前页的数据
        List<T> rows = mapper.queryData(query);
        return new PageList<>(total, rows);

    }

    @Override
    public void batch(List<Long> ids) {

    }
}
